package com.dongdongshop.controller;

import com.dongdongshop.data.Page;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.TbSellerService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("tbSeller")
public class TbSellerController {

    @DubboReference
    private TbSellerService tbSellerService;

    @RequestMapping("totbSeller")
    public String totbSeller(){
        return "admin/seller_1";
    }

    @RequestMapping("sellershow")
    @ResponseBody
    public Result sellershow(TbSeller tbSeller, @RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "3") Integer pageSize){
        Page page = tbSellerService.selectAll(tbSeller, pageNum, pageSize);
        if (page == null) {
            return Result.response(ResultEnum.ERROR);
        }
        return Result.response(ResultEnum.SUCCESS).setData(page);
    }
    @RequestMapping("details")
    @ResponseBody
    public Result details(TbSeller tbSeller){
        TbSeller Seller = tbSellerService.selectDetails(tbSeller);
        if (Seller == null) {
            return Result.response(ResultEnum.ERROR);
        }
        return Result.response(ResultEnum.SUCCESS).setData(Seller);
    }

    @RequestMapping("sellerPass")
    @ResponseBody
    public Result sellerPass(TbSeller tbSeller){
        boolean b = tbSellerService.updateBy(tbSeller);
        if (b){
            return Result.response(ResultEnum.SUCCESS);
        }return Result.response(ResultEnum.ERROR);
    }

    @RequestMapping("sellerPassing")
    @ResponseBody
    public Result sellerPassing(TbSeller tbSeller){
        boolean b = tbSellerService.updateBying(tbSeller);
        if (b){
            return Result.response(ResultEnum.SUCCESS);
        }return Result.response(ResultEnum.ERROR);
    }

    @RequestMapping("sellerNoPass")
    @ResponseBody
    public Result sellerNoPass(TbSeller tbSeller){
        boolean b = tbSellerService.updateByNo(tbSeller);
        if (b){
            return Result.response(ResultEnum.SUCCESS);
        }return Result.response(ResultEnum.ERROR);
    }
}
